]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
main: setup GJS profiler when GJS_TRACE_FD is set
authorChristian Hergert <chergert@redhat.com>
Wed, 5 Jun 2019 23:12:47 +0000 (16:12 -0700)
committerFlorian Müllner <florian.muellner@gmail.com>
Mon, 24 Jun 2019 15:05:46 +0000 (15:05 +0000)
This is the same environment variable that will be used in GJS to auto-
connect Sysprof to the GJS profiler when the gjs binary is used.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/573

meson.build
src/main.c

index ef52ef33e581f87ce9414f4a1438a5a7a76c43f4..69ea05c90068d7b2fce5b70fcb8d368f62a42c95 100644 (file)
@@ -20,7 +20,7 @@ gcr_req = '>= 3.7.5'
 gdesktop_req = '>= 3.7.90'
 gio_req = '>= 2.56.0'
 gi_req = '>= 1.49.1'
-gjs_req = '>= 1.57.2'
+gjs_req = '>= 1.57.3'
 gtk_req = '>= 3.15.0'
 json_glib_req = '>= 0.13.2'
 mutter_req = '>= 3.33.2'
index 24583778341b24ed4a3df9f54c459bec85054347..8d144aac6107b2a00f4fae0b50045f6a7cb8d94f 100644 (file)
@@ -198,6 +198,62 @@ shell_fonts_init (void)
   cogl_pango_font_map_set_use_mipmapping (fontmap, FALSE);
 }
 
+static void
+shell_profiler_init (void)
+{
+  ShellGlobal *global;
+  GjsProfiler *profiler;
+  GjsContext *context;
+  const char *enabled;
+  const char *fd_str;
+  int fd = -1;
+
+  /* Sysprof uses the "GJS_TRACE_FD=N" environment variable to connect GJS
+   * profiler data to the combined Sysprof capture. Since we are in control of
+   * the GjsContext, we need to proxy this FD across to the GJS profiler.
+   */
+
+  fd_str = g_getenv ("GJS_TRACE_FD");
+  enabled = g_getenv ("GJS_ENABLE_PROFILER");
+  if (fd_str == NULL || enabled == NULL)
+    return;
+
+  global = shell_global_get ();
+  g_return_if_fail (global);
+
+  context = _shell_global_get_gjs_context (global);
+  g_return_if_fail (context);
+
+  profiler = gjs_context_get_profiler (context);
+  g_return_if_fail (profiler);
+
+  if (fd_str)
+    {
+      fd = atoi (fd_str);
+
+      if (fd > 2)
+        {
+          gjs_profiler_set_fd (profiler, fd);
+          gjs_profiler_start (profiler);
+        }
+    }
+}
+
+static void
+shell_profiler_shutdown (void)
+{
+  ShellGlobal *global;
+  GjsProfiler *profiler;
+  GjsContext *context;
+
+  global = shell_global_get ();
+  context = _shell_global_get_gjs_context (global);
+  profiler = gjs_context_get_profiler (context);
+
+  if (profiler)
+    gjs_profiler_stop (profiler);
+}
+
 static void
 malloc_statistics_callback (ShellPerfLog *perf_log,
                             gpointer      data)
@@ -496,7 +552,9 @@ main (int argc, char **argv)
       dump_gjs_stack_on_signal (SIGSEGV);
     }
 
+  shell_profiler_init ();
   ecode = meta_run ();
+  shell_profiler_shutdown ();
 
   g_debug ("Doing final cleanup");
   _shell_global_destroy_gjs_context (shell_global_get ());